const host = "http://localhost:5555";
module.exports = ({url, data, method}) => {
  return new Promise((resolve, reject) => {
    wx.showLoading({
      title: '加载中',
    });
    wx.request({
      url: host+url,
      data,
      method,
      success: res=> {
        if(res.statusCode === 200) {
          resolve(res.data)
          wx.hideLoading()
        }else {
          wx.showToast({
            title: res.data.msg,
            icon: 'error'
          })
        }
      },
      fail: err=>{
        wx.showToast({
          title: '网络错误',
          icon: 'error'
        })
        reject(err)
      }
    })
  })
}
